import java.util.ArrayList;
import java.util.HashMap;

public class Demo {
    public int candy(int[] ratings) {
        int len = ratings.length;
        int[] candies = new int[len];
        for (int i = 0; i < len; i++) {
            candies[i] = 1;
        }
        for (int i = 0; i < len - 1; i++) {
            if (ratings[i] < ratings[i+1]) {
                candies[i+1]++;
            }
        }
        for (int i = len - 1; i > 0; i--) {
            if (ratings[i] < ratings[i-1]) {
                candies[i-1]++;
            }
        }
        int sum = 0;
        for (int i: candies) {
            sum += i;
        }
        return sum;
    }

    public static void main(String[] args) {
        Demo demo = new Demo();
        int[] ints = {1,3,2,2,1};
        int ret = demo.candy(ints);
    }
}
